package Object_demo;

public class toString {
    public static void main(String[] args) {
        student s=new student("启动器",3,'女');
        //默认输出地址
        System.out.println(s.toString());//输出s地址
        System.out.println(s);//输出s地址如果重写了toString方法就输出了地址
    }
}
class student{
    private String name;
    private int age;
    private char sex;

    public student() {
    }

    public student(String name, int age, char sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getSex() {
        return sex;
    }

    public void setSex(char sex) {
        this.sex = sex;
    }
    //重写toString方法

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", sex=" + sex +
                '}';
    }
}